package pl.koszolko.documentclustering.dao.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DataBaseConnectionManager {
	private static final String DATA_BASE = "jdbc:postgresql:";
	private static final String DATA_BASE_DRIVER = "org.postgresql.Driver";
	private String host;
	private String user;
	private String password;

	public DataBaseConnectionManager(String host, String user, String password) {
		setHost(host);
		setUser(user);
		setPassword(password);
		
		try {
			Class.forName(DATA_BASE_DRIVER).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	/**
	 * Zwraca polaczenie do bazy danych
	 * 
	 * @return polaczenie do bazy danych
	 * @throws ClassNotFoundException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 * @throws SQLException 
	 */
	public Connection getConnection() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
		Connection conn = null;
		conn = DriverManager.getConnection(DATA_BASE + host, user, password);
		
		return conn;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
